using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DragonAwakening.Game
{
    /// <summary>
    /// 
    /// </summary>
    public enum Sides : byte
    {
        North = 0,
        East = 1,
        South = 2,
        West = 3,
        Floor = 4,
        Sky = 5
    }

    public static class SideHelper
    {
        public static Sides RotateSide(Sides source, Sides rotation)
        {
            return (int)source < 4 ? (Sides)(((int)source + (int)rotation) % 4) : source;
        }
    }

    public static class PointHelper
    {
        public static Point Add(this Point src, Point dst)
        {
            return new Point(src.X + dst.X, src.Y + dst.Y);
        }
    }

    /// <summary>
    /// Map cell class.
    /// </summary>
    public class MapCell
    {
        /// <summary>
        /// Walls information
        /// </summary>
        private byte[] Walls = new byte[6];

        /// <summary>
        /// Creatures information.
        /// </summary>
        public byte[] Creatures;

        /// <summary>
        /// Constructs new map cell.
        /// </summary>
        public MapCell(int x, int y, byte wallNorth, byte wallSouth, byte wallEast, byte wallWest, byte floor, byte sky)
        {
            this.X = x;
            this.Y = y;
            this.Walls[(int)Sides.North] = wallNorth;
            this.Walls[(int)Sides.South] = wallSouth;
            this.Walls[(int)Sides.East] = wallEast;
            this.Walls[(int)Sides.West] = wallWest;
            this.Walls[(int)Sides.Floor] = floor;
            this.Walls[(int)Sides.Sky] = sky;
        }

        /// <summary>
        /// Constructs new map cell with data.
        /// </summary>
        public MapCell(int x, int y, byte wallNorth, byte wallSouth, byte wallEast, byte wallWest, byte floor, byte sky, byte[] creatures)
        {
            this.X = x;
            this.Y = y;
            this.Walls[(int)Sides.North] = wallNorth;
            this.Walls[(int)Sides.South] = wallSouth;
            this.Walls[(int)Sides.East] = wallEast;
            this.Walls[(int)Sides.West] = wallWest;
            this.Walls[(int)Sides.Floor] = floor;
            this.Walls[(int)Sides.Sky] = sky;

            this.Creatures = creatures;
        }

        /// <summary>
        /// X coordinate of the map.
        /// </summary>
        public int X { get; set; }
        
        /// <summary>
        /// Y coordinate of the map.
        /// </summary>
        public int Y { get; set; }

        /// <summary>
        /// Gets the map cell information.
        /// </summary>
        public short GetWall(Sides side)
        {
            return this.Walls[(int)side];
        }

        /// <summary>
        /// Checks if there are any creatures onat this cell.
        /// </summary>
        /// <returns></returns>
        public bool HasCreatures()
        {
            return this.Creatures != null;
        }
    }
}
